<style type="text/css">
form .red { color: red; }
</style>
<script type="text/javascript" src="/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
  tinyMCE.init({
    width : "86%",
    height : "350px",
    mode : "textareas",
    theme : "advanced",
    language: "zh-cn",
    plugins : "autolink,lists,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,advlist,autosave",

    // Theme options
    theme_advanced_buttons1 : "newdocument,|,bold,italic,underline,strikethrough,|,forecolor,backcolor,|,bullist,numlist,|,justifyleft,justifycenter,justifyright,justifyfull,formatselect,fontselect,fontsizeselect,|,fullscreen",
    //theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
    //theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
    // theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "left",
    theme_advanced_statusbar_location : "bottom",
    theme_advanced_resizing : true,

    // Example content CSS (should be your site CSS)
    content_css : "/tiny_mce/themes/advanced/skins/default/content.css"

  });
</script>

<%= form_for(@post) do |f| %>
  <% if @post.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2>

      <ul>
      <% @post.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= f.label :title, '标题', :class=>"red" %><br />
    <%= f.text_field :title, :style=>'width:450px;' %>
  </div>
  <div class="field">
    <%= f.label :content, '内容', :class=>"red" %><br />
    <%= f.text_area :content, :style=>'width:650px; height:200px;' %>
  </div>
  <div class="field">
    <%= f.label :pic, '图片', :class=>"red" %><br />
    <%= f.text_field :pic, :style=>'width:500px' %>
  </div>
  <div class="field">
    <%= f.label :video, '视频' %><br />
    <%= f.text_field :video, :style=>'width:500px' %>
  </div>
  <div class="field">
    <%= f.label :cateid, '类别', :class=>"red" %><br />
    <%= select(:post, :cateid, Category.all.collect {|p| [ p.viewname, p.id ] }, { :include_blank => true }) %>
  </div>
  <div class="field">
    <%= f.label :paras, '单元参数' %><br />
    <%= f.text_field :paras %>
  </div>
  <div class="field">
    <%= f.label :source, '来源' %><br />
    <%= f.number_field :source %>
  </div>
  <div class="field">
    <%= f.label :tag, '标签' %><br />
    <%= f.text_field :tag %>
  </div>
  <div class="field">
    <%= f.label :hit, '点击次数' %><br />
    <%= f.number_field :hit, :style=>'width:80px;' %>
  </div>
  <div class="field">
    <%= f.label :url, '自定义网址' %><br />
    <%= f.text_field :url %>
  </div>
  <div class="field">
    <%= f.label :userid, '用户编号' %><br />
    <%= f.text_field :userid, :value=>session[:adminer].id, :readonly=>'true' %>
  </div>
  <div class="field">
    <%= f.label :userip, '用户IP' %><br />
    <%= f.text_field :userip, :value=>request.remote_ip, :readonly=>'true' %>
  </div>
  <div class="field">
    <%= f.label :sortid, '排序编号' %><br />
    <%= f.number_field :sortid, :style=>'width:80px;' %>
  </div>
  <div class="field">
    <%= f.label :postdate, '发布日期', :class=>"red" %><br />
    <%= f.text_field :postdate %>
  </div>
  <div class="actions">
    <%= f.submit :class=>'btn btn-primary' %>
  </div>
<% end %>


<script type="text/javascript">
$(document).ready(function(){
  // 类别必填
  $('input[type="submit"]').click(function(){
    if($('#post_cateid').val()=='') {
      alert('请选择类别。');
      $('#post_cateid').focus();
      return false;
    }
  });
});
</script>